package com.ccc.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ccc.dao.DemandDao;
import com.ccc.model.Demand;
import com.ccc.util.dao.UtilDao;

@Component("demandDao")
public class DemandDaoImpl implements DemandDao {
	private UtilDao utilDao;

	@Override
	public void addDemand(Demand demand) {
		utilDao.save(demand);
	}

	@Override
	public void deleteDemand(Demand demand) {
		utilDao.delete(demand);
	}

	@Override
	public void updateDemand(Demand demand) {
		utilDao.update(demand);
	}

	@Override
	public Demand findDemand(int id) {
		return utilDao.find(Demand.class, id);
	}

	public UtilDao getUtilDao() {
		return utilDao;
	}
	@Resource
	public void setUtilDao(UtilDao utilDao) {
		this.utilDao = utilDao;
	}

	@Override
	public Demand findDemand() {
		List<Demand> list = utilDao.find("from Demand d order by d.demandId desc", null);
		if(list!=null&list.size()>0){
			return list.get(0);
		}return null;
	}

}
